/*
 * @Author: hinak0 hinak0@qq.com
 * @Date: 2022-10-04 16:36:52
 * @FilePath: /boss-timer/vue.config.js
 * @Description:
 * Copyright (c) 2022 by hinak0 hinak0@qq.com, All Rights Reserved.
 */
module.exports = {
	productionSourceMap: false,
	outputDir: 'server/src/main/resources/static',
	devServer: {
		proxy: 'http://127.0.0.1:9999',
	},
	chainWebpack: (config) => {
		if (process.env.NODE_ENV === 'production') {
			var externals = {
				vue: 'Vue',
				axios: 'axios',
				'element-ui': 'ELEMENT',
				dayjs: 'dayjs',
			}
			config.externals(externals)
			const cdn = {
				css: [
					// element-ui css
					'https://cdn.bootcdn.net/ajax/libs/element-ui/2.12.0/theme-chalk/index.css',
				],
				js: [
					// dayjs
					'https://unpkg.com/dayjs@1.8.21/dayjs.min.js',
					// vue
					'https://cdn.bootcdn.net/ajax/libs/vue/2.6.10/vue.min.js',
					// axios
					'https://cdn.bootcdn.net/ajax/libs/axios/0.18.0/axios.min.js',
					// element-ui js
					'https://cdn.bootcdn.net/ajax/libs/element-ui/2.12.0/index.js',
				],
			}
			// 通过 html-webpack-plugin 将 cdn 注入到 index.html 之中
			config.plugin('html').tap((args) => {
				args[0].cdn = cdn
				return args
			})
		}
	},
}
